from chernc.treediff.gumtree.actions.model.tree_action import TreeAction
from chernc.treediff.gumtree.tree.tree import TreeLike


class TreeAddition(TreeAction):
    def __init__(self, node: TreeLike, parent: TreeLike, pos: int):
        super().__init__(node)
        self.parent = parent
        self.pos = pos

    def get_parent(self) -> TreeLike:
        return self.parent

    def get_position(self) -> int:
        return self.pos

    def __str__(self) -> str:
        return f"===\n{self.get_name()}\n---\n{self.node.to_tree_string()}\nto\n{str(self.parent) if self.parent else 'root'}\nat {self.pos}"

    def __eq__(self, other) -> bool:
        if not isinstance(other, TreeAddition):
            return False
        return super().__eq__(other) and self.parent == other.parent and self.pos == other.pos
